package cn.myframe.controller.sys;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.myframe.controller.AbstractController;
import cn.myframe.controller.BaseController;
import cn.myframe.service.BaseService;
import cn.myframe.utils.core.R;
import cn.myframe.entity.sys.SysBaseDataTypeEntity;
import cn.myframe.service.sys.SysBaseDataTypeService;


/**
 * 字典类型
 * 
 * @author ynz
 * @email ynz@myframe.cn
 * @date 2018-08-06 22:47:57
 */
@RestController
@RequestMapping("/sys/sysbasedatatype")
public class SysBaseDataTypeController  extends AbstractController implements BaseController<SysBaseDataTypeEntity,BaseService<SysBaseDataTypeEntity>>{
	@Autowired
	private SysBaseDataTypeService sysBaseDataTypeService;
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list",method = {RequestMethod.GET})
	@RequiresPermissions("sysbasedatatype:list")
	public R list(@RequestParam Map<String, Object> params){
		return this.defaultList(params);
	}	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{typeId}")
	@RequiresPermissions("sysbasedatatype:info")
	public R info(@PathVariable("typeId") Long id){
		return this.defaultInfo(id,"sysBaseDataType");
	}
	
	/**
	 * 新增保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("sysbasedatatype:save")
	public R save(@RequestBody SysBaseDataTypeEntity sysBaseDataType){		
		return this.defaultSave(sysBaseDataType);
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("sysbasedatatype:delete")
	public R delete(@RequestBody Long[] ids){		
		return this.defaultDelete(ids);
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")	
	@RequiresPermissions("sysbasedatatype:update")
	public R update(@RequestBody SysBaseDataTypeEntity sysBaseDataType){		
		return this.defaultUpdate(sysBaseDataType);
	}
	
   /**
    * 提交,审核
    */
	@RequestMapping("/audit")	
	@RequiresPermissions(value={"sysbasedatatype:submit","sysbasedatatype:auditpass","sysbasedatatype:auditnopass"},logical=Logical.OR)
	public R audit(@RequestBody Long[] ids ,@RequestParam Integer status){
		return this.defaultAudit(ids, status);
	}
	
   /**
	* 检验字段值重复
	*/
    @RequestMapping("/checkExist")
    @ResponseBody
    public String checkExist(String id,String value,String columnName){
        return this.defaultCheckExist(id, value, columnName);
    }
    
    /**
     * 字典类型树
     * @return
     */
    @ResponseBody
	@RequestMapping(value = "/treeList",method = {RequestMethod.GET})
    public R getTree(){
    	List<SysBaseDataTypeEntity> treeList = sysBaseDataTypeService.selectByMap(new HashMap<>());
    	return R.ok().put("treeList", treeList);
    }
    
    
    public SysBaseDataTypeService getService(){
		return sysBaseDataTypeService;
	}
	
}
